package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.aliyuncs.exceptions.ClientException;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.OrdersettinglistService;
import com.itheima.utils.DateUtils;
import com.itheima.utils.SMSUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/ordersettinglist")
public class OrdersettinglistController {
    @Reference
    private OrdersettinglistService ordersettinglistService;
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
    return ordersettinglistService.pageQuery(queryPageBean);
    }

    @RequestMapping("/sendMsg")
    public Result sendMsg(@RequestBody Map map) throws Exception {
        Date orderDate = DateUtils.parseString2Date((String)map.get("orderDate"));
        String code = DateUtils.parseDate2String(orderDate);
        String phoneNumber = (String) map.get("phoneNumber");
        System.out.println(code);
        try {
            SMSUtils.sendShortMessage(SMSUtils.VALIDATE_CODE,phoneNumber,"1234");
            return new Result(true,"短信发送成功");
        } catch (ClientException e) {
            e.printStackTrace();
            return new Result(false,"发送失败");
        }
    }
}
